package com.li.algorithm.leetcode.hot100;
public class Test31 {
    public ListNode reverseKGroup(ListNode head, int k) {
        //标记起点，到k之后开始反转
        //每次到k记录该节点的下一节点
        int count = 0;
        ListNode p = head;
        ListNode nextK;
        ListNode start = head;
        boolean first = true;
        while (p != null) {
            if (count == k) {
                nextK = p.next;
                //反转链表
                ListNode q = start.next;
                for (int i = 0; i < k; i++) {
                    ListNode temp = q.next;
                    q.next = start;
                    start = q;
                    q = temp;
                }
                start.next = nextK;
                count = 0;
            }
            p = p.next;
            count++;
        }
        return null;
    }
}
